
public class BinarySearchTree<S extends Comparable<? super S>> {
	public int contador=0;
	private S element;
	private BinarySearchTree<S> left;
	private BinarySearchTree<S> right;
	
	private BinarySearchTree(S element, BinarySearchTree<S> left, BinarySearchTree<S> right){
		this.element=element;
		this.left=left;
		this.right=right;
	}
	
	public String toString(){
		return this.recToString();	
	}
	
	private String recToString(){
		//System.out.println("soy "+element);
		String ans=new String();
		if(left!=null){
			ans+=left.recToString();
		}
		ans+=" "+element.toString();
		if(right!=null){
			ans+=right.recToString();
		}
		return ans;
	}
	
	public BinarySearchTree(S ascendentArray[]){
		System.out.println(arrayToTree(ascendentArray,0,ascendentArray.length-1));
	}
	
	private void arrayToTree(S ascArray[]){
	}
	
	private BinarySearchTree<S> arrayToTree(S ascArray[], int from, int to){
		System.out.println("from:"+from+"to:"+to);
				
		if(from<0){
			System.out.println(ascArray[0]);
			return new BinarySearchTree<S>(ascArray[0],
					null,
					null);
		}
		if(to>ascArray.length){
			System.out.println(ascArray[ascArray.length]);
			return new BinarySearchTree<S>(ascArray[ascArray.length],
					null,
					null);
		}
		
		if(from<to&&to<ascArray.length){
			int median=(to+from)/2;
			System.out.println("mediana "+ascArray[median]);
			return new BinarySearchTree<S>(ascArray[median], 
					arrayToTree(ascArray,from,median-1),
					arrayToTree(ascArray,median+1,to));
		}
		
		if(from==to){
			System.out.println("pasa esto");
			if(from==0){
				System.out.println("pasa bla");
				return new BinarySearchTree<S>(ascArray[0],
						null,
						new BinarySearchTree<S>(ascArray[1],null,null));
			}
			if(from==ascArray.length){
				System.out.println("pasa bli");
				return new BinarySearchTree<S>(ascArray[ascArray.length],
						new BinarySearchTree<S>(ascArray[1],null,null),
						null);
			}
		}
		
		/*
		for(int i=from;i<to;i++){
			System.out.println(ascArray[i]);
		}*/
		return null;
	}
}
